package io.renren.modules.personal.service.impl;

import io.renren.modules.personal.dao.PersonalDao;
import io.renren.modules.sys.dto.AttentionAndFansDto;
import io.renren.modules.sys.dto.LikeDto2;
import io.renren.modules.forYoung.entity.AttentionAndFans;
import io.renren.modules.sys.entity.UserEntity;
import io.renren.modules.personal.service.PersonalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class PersonalServiceImpl implements PersonalService {

    @Autowired
    PersonalDao personalDao;

    @Override
    public UserEntity getUserAndCount(Map map) {
        return personalDao.getUserAndCount(map);
    }

    @Override
    public void saveAttention(Map map) {
        personalDao.saveAttention(map);
    }

    @Override
    public int delAttention(Map map) {
        return personalDao.delAttention(map);
    }

    @Override
    public AttentionAndFans getEntityByUser(Long userId) {
        return personalDao.getEntityByUser(userId);
    }

    @Override
    public List getMyAttentionId(Long userId) {
        return personalDao.getMyAttentionId(userId);
    }

    @Override
    public List getFansIdList(Long userId) {
        return personalDao.getFansIdList(userId);
    }

    @Override
    public AttentionAndFansDto getFandsEntityByUserId(long userIdd) {
        return personalDao.getFandsEntityByUserId(userIdd);
    }

    @Override
    public AttentionAndFans isAttention(long userId, long userIdd) {
        return personalDao.isAttention(userId,userIdd);
    }

    @Override
    public AttentionAndFans checkIsAttention(Long userId, Long userIdd) {
        return personalDao.checkIsAttention(userId,userIdd);
    }

    @Override
    public List getMyFansList(Map map) throws UnsupportedEncodingException {
        List<AttentionAndFansDto> list=personalDao.getMyFansList(map);
        for(AttentionAndFansDto a:list){
            a.setNickName(new String(a.getNickNameB(),"utf-8"));
        }
        return list;
    }

    @Override
    public List getMyAttentionList(Map map) {
        return personalDao.getMyAttentionList(map);
    }

    @Override
    public AttentionAndFans getEntityByUserIdAndFansId(Map map) {
        return personalDao.getEntityByUserIdAndFansId(map);
    }

    @Override
    public void updateHuxiangguanzhu(Map map) {
        personalDao.updateHuxiangguanzhu(map);
    }

    @Override
    public void updateHuxiangguanzhuToOne(Map map) {
        personalDao.updateHuxiangguanzhuToOne(map);
    }

    @Override
    public List getSeachList(Map<String, Object> params) throws UnsupportedEncodingException {
        List<AttentionAndFansDto> list=personalDao.getSeachList(params);
        setUserDto(list);
        return list;
    }

    @Override
    public int updataMyIntroduction(Map map) {
        return personalDao.updataMyIntroduction(map);
    }

    @Override
    public int getMyCourseCollectionCount(Map map) {
        return personalDao.getMyCourseCollectionCount(map);
    }

    @Override
    public int getMyForYoungCollectuinCount(Map map) {
        return personalDao.getMyForYoungCollectuinCount(map);
    }

    @Override
    public List getMyCollectionShareList(Map map) {
        return personalDao.getMyCollectionShareList(map);
    }

    @Override
    public List<Integer> getForYoungId(Map map) {
        return personalDao.getForYoungId(map);
    }

    @Override
    public String getForYoungImgs(int id) {
        return personalDao.getForYoungImgs(id);
    }

    @Override
    public List<LikeDto2> getLikeManInfo(Map map) {
        return personalDao.getLikeManInfo(map);
    }

    @Override
    public int getSchoolIdBySchoolName(Map map) {
        return personalDao.getSchoolIdBySchoolName(map);
    }

    @Override
    public void updateSchoolById(Map map) {
        personalDao.updateSchoolById(map);
    }

    @Override
    public List selectSchool() {
        return personalDao.selectSchool();
    }

    @Override
    public List getUsers(byte[] name) throws UnsupportedEncodingException {
        List<UserEntity> list=personalDao.getUsers(name);
        setUserNickName(list);
        return list;
    }

    @Override
    public List getForYoungByUserId(Long userId) {
        return personalDao.getForYoungByUserId(userId);
    }

    @Override
    public String getschoolNameById(Map map) {
        return personalDao.getschoolNameById(map);
    }

    public void setUserDto(List<AttentionAndFansDto> userDto) throws UnsupportedEncodingException {
        for(AttentionAndFansDto a:userDto){
            a.setNickName(new String(a.getNickNameB(),"utf-8"));
        }
    }

    public void setUserNickName(List<UserEntity> userNickName) throws UnsupportedEncodingException {
        for(UserEntity u:userNickName){
            u.setNickName(new String(u.getNickNameB(),"utf-8"));
        }
    }


    public  String getIsAttention(Map map) {


        return personalDao.getIsAttentin(map);
    }

}
